# !/usr/bin/python
# _*_ coding: utf-8 _*_
# @Time : 2021/5/25 11:42 上午
# @Author : liujun
# @File : cnf_utils.py
# @desc : 配置文件工具类
import os
import configparser


class MyCnf(object):

    def __init__(self, config_filename='/resource/my_config.conf'):
        project_path = os.path.abspath(os.path.dirname(__file__))
        file_path = project_path[: len(project_path)-5] + config_filename
        self.cf = configparser.ConfigParser()
        self.cf.read(file_path)

    def __get_options(self, section):
        return self.cf.options(section)

    def get_value(self, section, option):
        value = self.cf.get(section, option)
        return int(value) if value.isdigit() else value

    def get_content(self, section):
        config = {}
        for option in self.__get_options(section):
            value = self.cf.get(section, option)
            config[option] = int(value) if value.isdigit() else value
        return config
